package lunsfordhall.androidapp;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;


public class Physics_form_1 extends Activity{// activation class of over all program

	public void onCreate(Bundle savedInstanceState) {// bundles all of work and saves
        super.onCreate(savedInstanceState);
        
        setContentView(R.layout.main);
        
        final EditText edittext = (EditText) findViewById(R.id.edittext);// enter text box for distance
        final EditText edittext2 = (EditText) findViewById(R.id.edittext2);// enter text box for velocity intital
        final EditText edittext3 = (EditText) findViewById(R.id.edittext3);// enter text box for velocity final
        final EditText edittext4 = (EditText) findViewById(R.id.edittext4);// enter text box for time
     
        final Button button = (Button) findViewById(R.id.button1);//makes button
        
        button.setOnClickListener(new OnClickListener() {//reads button action
        	public void onClick(View v) {// when click happens this ensues
        		 TextView t = (TextView)findViewById(R.id.textview);// the variable for the output of awnser

             	double Δd = Double.parseDouble(edittext.getText().toString());//parsing the double variables
             	
             	double vi = Double.parseDouble(edittext2.getText().toString());//parsing the double variables
             	
             	double vf = Double.parseDouble(edittext3.getText().toString());//parsing the double variables
             	
             	double Δt = Double.parseDouble(edittext4.getText().toString());//parsing the double variables
             	
             	  	
             	double Time=0;//sets output to starter zero
             	double Distance=0;//sets output to starter zero
             	double velocity=0;//sets output to starter zero
             	
             	if(Δd>0 && vi>0 && Δt==0){//defines when to solve for time
             		
             	 Time = Δd/2*(vi+vf);//solution equation
             	
                 t.setText(String.valueOf(Time));// outputs answer to text field                
             	}
             	
             	else if(Δt>0 && vi>0 && Δd==0){//defines when to solve for distance
                 Distance = (vi+vf)*Δt;//solution equation
             	 t.setText(String.valueOf((Distance/2)));// outputs answer to text field   
             	
                 }
             	else if(Δd>0 && Δt>0 && vi==0 && vf==0){//defines when to solve for velocity initial
                 velocity =2*Δd/Δt;//solution equation
                 
             	 t.setText(String.valueOf(velocity));// outputs answer to text field   
             	 
                 }else{// else wise does nothing
                 	
                 	}	    
        		}
        	});   
		}
   }
        
	

